package com.monitor.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.monitor.dao.ErpManagementMapper;
import com.monitor.entity.ErpManagement;
import com.monitor.service.ErpManagementService;
import com.monitor.util.Result;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 检测维护销售维修工作单表 服务实现类
 * </p>
 *
 * @author LX
 * @since 2018-09-28
 */
@Service
@Transactional
public class ErpManagementServiceImpl extends ServiceImpl<ErpManagementMapper, ErpManagement> implements ErpManagementService {

	@Resource
	private ErpManagementMapper erpManagementMapper;

	@Override
	public Map<String, Object> selectTongYong(String sql){
		Map<String, Object> map=erpManagementMapper.selectTongYong(sql);
		return map;
	}
	@Override
	public Map<String, Object> selectTong(String startTime, String endTime) {
		// TODO Auto-generated method stub
		StringBuffer sb=new StringBuffer(" ");
		if(startTime!=null&&!startTime.equals("")) {
			sb.append(" and dt>='"+startTime+"'");
		}
		if(endTime!=null&&!endTime.equals("")) {
			sb.append(" and dt<='"+endTime+"'");
		}
		Map<String, Object> map=erpManagementMapper.selectTong(sb.toString());
		return map;
	}

	@Override
	public Map<String, Object> selectByWorkPlace(String custName, String startTime, String endTime) {
		// TODO Auto-generated method stub
		StringBuffer sb=new StringBuffer(" ");
		if(startTime!=null&&!startTime.equals("")) {
			sb.append(" and dt>='"+startTime+"'");
		}
		if(endTime!=null&&!endTime.equals("")) {
			sb.append(" and dt<='"+endTime+"'");
		}
		Map<String, Object> map=erpManagementMapper.selectByWorkPlace(custName, sb.toString());
		return map;
	}

	@Override
	public Result<Map<String, Object>> selectByWorkPlaceList(String custName, String startTime, String endTime) {
		// TODO Auto-generated method stub
		Map<String,Object>  result=new HashMap<>();
		StringBuffer sb=new StringBuffer(" ");
		if(startTime!=null&&!startTime.equals("")) {
			sb.append(" and dt>='"+startTime+"'");
		}
		if(endTime!=null&&!endTime.equals("")) {
			sb.append(" and dt<='"+endTime+"'");
		}
		Map<String, Object> map=erpManagementMapper.selectByWorkPlaceDateil(custName, sb.toString());
		result.put("topMap", map);
		List<ErpManagement> list=erpManagementMapper.selectByWorkPlaceDateilList(custName, sb.toString());
		result.put("custList", list);
		return new Result<Map<String,Object>>(result, list.size()+1);
	}

}
